@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}
<script type="text/javascript">
    window.onload = function () {
        
    }
    function AddMoney3() {
        var type = document.getElementById("types").value;
        var number = document.getElementById("number").value;
        var remarks = document.getElementById("remarks").value;
        var date = document.getElementById("date").value;
        var userName = document.getElementById("userName").value;
        $.ajax({
            type: "post",
            url: "/Money3/AddMoney3",
            data: { "id": userName, "type": type, "number": number, "remarks": remarks, "date": date },
            success: function (data) {
                SelectMoney3();
            },
            error: function (err) { alert(err); }
        });
    }
    function SelectMoney3() {
        var userName = document.getElementById("userName").value;
        var selecttype = document.getElementById("selecttype").value;
        $.ajax({
            type: "post",
            url: "/Money3/SelectMoney3",
            data: { "id": userName, "selecttype": selecttype},
            success: function (data) {
                SetTable(data);
            },
            error: function (err) { alert(err); }
        });
    }
    function SetTable(data) {
        var max = 0;
        var obj = JSON.parse(data);
        var html = "";
        for (var i = 0; i < obj.length; i++) {
            html += "<tr>";
            html += "<td>" + obj[i].changeTime + "</td>";
            var type = obj[i].type == "0" ? "支出" : "收入";
            html += "<td>" + type + "</td>";
            html += "<td>" + obj[i].value + "</td>";
            html += "<td>" + obj[i].remarks + "</td>";
            html += "<td><span onclick=\"deldata('" + obj[i].id + "')\"> 删除</span</td>";
            html += "</tr>";
            max += Number(obj[i].value);
        }
        document.getElementById("bbddyy").innerHTML = html;
        document.getElementById("all").innerHTML = max;
    }
    function deldata(id) {
        $.ajax({
            type: "post",
            url: "/Money3/Deldata",
            data: { "id": id },
            success: function (data) {
                SelectMoney3();
            },
            error: function (err) { alert(err); }
        });
    }
</script>
<div>
    <span>用户名</span><input type="text" id="userName" />
    <span>类型</span><input type="text" id="selecttype" />
    <input type="button" value="查询" onclick="SelectMoney3()" />
</div>
<div>
    <div>添加</div>
    <span>类型</span><input type="text" id="types" />
    <span>数额</span><input type="text" id="number" />
    <span>备注</span><input type="text" id="remarks" n />
    <span>日期</span><input type="date" id="date" />
    <input type="button" value="提交" onclick="AddMoney3()" />
</div>

<div>
    <div id="all"></div>
    <table class="table">
        <thead>
            <tr>
                <th>时间</th>
                <th>类型</th>
                <th>值</th>
                <th>备注</th>
                <th>删除</th>
            </tr>
        </thead>
        <tbody id="bbddyy">
        </tbody>
    </table>
</div>